package jsd2302.src.exception;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/** 异常处理机制再IO操作中的运用 */
public class FinallyDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        /*
        FileOutputStream fos=null;
        try{
            fos=new FileOutputStream("fos.dat");
        }catch(IOException e){
            System.out.println("出现IO异常并解决了");

        }finally{
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("程序结束了");
        
         */
        FileOutputStream fos = null;
        try{
            fos=new FileOutputStream("fos.txt");
        }catch(IOException e){
            System.out.println("出错并解决了");
        }finally{
            try{
                fos.close();
            }catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("程序结束了");
    }
}
